//this program using to paint the graph;

#include "mainwindow.h"
#include <QApplication>
#include <QGraphicsScene>
#include <QGraphicsRectItem>
#include <QGraphicsView>
#include "math.h"

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    QGraphicsScene scence;  //定义一个场景；
    scence.setBackgroundBrush(Qt::red);

    QPen pen; //定义一个画笔；
    pen.setColor(QColor(0,160,320));
    pen.setWidth(10);

    QGraphicsRectItem *rectitem=new QGraphicsRectItem(); //定义四边形
    rectitem->setRect(50,50,80,80);
    rectitem->setPen(pen);
    rectitem->setBrush(QBrush(QColor(255,0,255)));  //刷形状内部颜色
    rectitem->setFlag(QGraphicsItem::ItemIsMovable);

    QGraphicsLineItem *lineitem=new QGraphicsLineItem();  //定义直线图元
    lineitem->setLine(50,50,100,100);
    lineitem->setPen(pen);
    lineitem->setFlag(QGraphicsItem::ItemIsMovable);

    QGraphicsPathItem *pathitem=new QGraphicsPathItem();
    QPainterPath path;
    path.moveTo(150,100);
    for(int i=0;i<5;i++)
    {
        path.lineTo(50+40*cos(0.8*i*M_PI),50+40*sin(0.8*i*M_PI));  //五角星
    }
    path.closeSubpath();   //自动将路径首尾连接；
    pathitem->setPath(path);
    pathitem->setPen(pen);
    pathitem->setBrush(QBrush(QColor(0,255,0)));
    pathitem->setFlag(QGraphicsItem::ItemIsMovable);

    QGraphicsPolygonItem *polyitem =new QGraphicsPolygonItem();
    QPolygonF polygonf;
    polygonf<<QPointF(-50.0,60.0)<<QPointF(-60.0,50.0)
           <<QPointF(-70.0,80.0)<<QPointF(50.0,-80.0);
    polyitem->setPolygon(polygonf);
    polyitem->setPen(pen);
    polyitem->setBrush(QBrush(QColor(0,0,255)));
    polyitem->setFlag(QGraphicsItem::ItemIsMovable);


    scence.addItem(lineitem);
    scence.addItem(rectitem);
    scence.addItem(pathitem);
    scence.addItem(polyitem);

    QGraphicsView view(&scence);
    view.resize(256,256);
    view.show();

    return a.exec();
}
